package com.example.helloworldtext2.holder;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.helloworldtext2.R;
import com.example.helloworldtext2.components.CUserAvatar;
import com.example.helloworldtext2.model.Article;

public class HomeViewHolder extends RecyclerView.ViewHolder {

    private ImageView coverImage;
    private TextView titleText;
    private CUserAvatar cUserAvatar;
    public HomeViewHolder(@NonNull View itemView) {
        super(itemView);
        coverImage = itemView.findViewById(R.id.coverImage);
        titleText = itemView.findViewById(R.id.titleText);
        cUserAvatar = itemView.findViewById(R.id.cUserAvatar);
//        监听事件
        cUserAvatar.setOnClickListener(goUserCenter());
    }

    public void bind(Article item) {
        titleText.setText(item.getTitle());
        cUserAvatar.setNickname(item.getAuthorName());
        Glide.with(itemView.getContext())
                .load(item.getAuthorAvatar())
                .placeholder(R.drawable.avater)
                .circleCrop()
                .into(cUserAvatar.getUserAvatarView());
        // 使用Glide加载图片
        Glide.with(itemView.getContext())
                .load(item.getCoverImageUrl())
                .placeholder(R.drawable.avater)
                .into(coverImage);
    }
    public View.OnClickListener goUserCenter(){
        return new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("goUrl", "跳转到用户中心");
            }
        };
    }
}